<template>
	<view v-if="display">
		<view class="cash_box">
			<view class="cash_card">
				<text>到账银行卡</text>
				<view class="card">
					<view class="lefts">
						<img :src="data.bank_logo" alt="">
						<h5>{{data.bank_name}}({{bank_card_number}})</h5>
					</view>
					<view class="rights" @click="replace_card">
						<text>更换</text>
					</view>
				</view>
			</view>
			<view class="cash_quota">
				<text>提现金额(元)</text>
				<view class="quota">
					<view class="">
						<h1>￥</h1>
						<input type="number" v-model="amount" placeholder="输入提现金额" @input="_input">
					</view>
					<text @click="whole">全部</text>
				</view>
				<view class="withdrawal_money">可提现金额(元) <text>{{money}}</text></view>
			</view>
			<view class="cash_Tips">
				<text>温馨提示：</text>
				<!-- <text>1、结算方式：{{status.clearing_form == 1?'秒结算':'月结算'}}</text> -->
				<text>1、单次提现最低{{status.withdrawal_min_money}}元，最高{{status.withdrawal_max_money}}元</text>
				<text>2、提现时间：工作日【{{status.withdrawal_start_time}}-{{status.withdrawal_end_time}}】</text>
				<text>3、手续费：{{status.service_charge}},税率(%)：{{status.tax_rate}}</text>
				<text>4、单日提现次数：{{status.withdrawal_number}}</text>
				<text v-if="status.remarks != '' && status.remarks != null">备注信息：{{status.remarks}}</text>
			</view>
			<view class="order" v-if="status.is_open == 1&&amount != ''" @click="verify">提现</view>
			<view class="order" style="background-color: #eee;" v-else>提现</view>
		</view>
	</view>
</template>

<script>
	import {
		data
	} from '../../../../uni_modules/uview-ui/libs/mixin/mixin'
	export default {
		data() {
			return {
				card: '',
				data: {},
				money: 0,
				bank_card_number: '',
				display: false,
				amount: '',
				type: '',
				balance_type_id: null,
				status: {}
			}
		},
		onNavigationBarButtonTap() {
			uni.navigateTo({
				url: '/pages/mine/profit/Cash/Cash_info'
			})
		},
		onShow() {
			this._cash()
			this._status()
			this.getBalance()
		},
		methods: {
			//获取提现数据
			async _cash() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'Bankcard/getBankCardDetail',
					data: {},
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (res.data !== null) {
						this.display = true
						this.data = res.data
						this.bank_card_number = this.data.bank_card_number.slice(-4)
					} else {
						let _this = this
						uni.showModal({
							title: '提示',
							content: '未绑定银行卡，是否绑定银行卡',
							success: function(ress) {
								if (ress.confirm) {
									_this.bank_card()
								} else if (ress.cancel) {
									uni.navigateBack({});
								}
							}
						});
					}
				}
			},
			//银行卡管理
			bank_card() {
				uni.navigateTo({
					url: '/pages/mine/profit/bank_card/bank_card'
				})
			},
			//获取提现状态
			async _status() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Withdraw/getWithdrawStateNew'
				});
				if (res.code == 200) {
					this.status = res.data
				}
			},
			//获取余额
			async getBalance() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'Balance/getBalance'
				});
				if (res.code == 200) {
					this.money = res.data
				}
			},
			//全部
			whole() {
				this.amount = this.money
			},
			//验证提现
			verify() {
				if (parseFloat(this.amount) >= parseFloat(this.status.withdrawal_min_money)) {
					var time = new Date()
					let hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours()
					let minute = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes()
					let _time = hour + ':' + minute
					if (_time > this.status.withdrawal_start_time && _time < this.status.withdrawal_end_time) {
						this.Cash()
					} else {
						uni.showToast({
							title: '不在提现时间范围内',
							icon: 'none',
							duration: 2000
						})
					}
				} else {
					uni.showToast({
						title: '单次提现最低' + this.status.withdrawal_min_money + '元',
						icon: 'none',
						duration: 2000
					})
				}
			},
			_input() {
				if (parseFloat(this.amount) > parseFloat(this.money)) {
					uni.showToast({
						title: '超出提现范围',
						icon: 'none',
						duration: 2000
					})
					this.amount = ''
				}
			},
			//点击提现
			async Cash() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'Withdraw/withdrawCash',
					data: {
						balance_type_id: this.balance_type_id,
						withdrawal_money: this.amount,
						balance_types: this.type
					}
				});
				uni.hideLoading()
				if (res.code == 200) {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000,
						success() {
							setTimeout(function() {
								uni.navigateBack({
									delta: 2
								})
							}, 1500)
						}
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 3000,
					})
					this.amount = ''
				}

			},
			replace_card() {
				uni.navigateTo({
					url: '/pages/mine/profit/bank_card/bank_card'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cash_box {
		margin: 30rpx;
		padding: 30rpx;
		box-sizing: border-box;
		background-color: #fff;

		.cash_card {
			padding: 20rpx 0;
			display: flex;
			flex-direction: column;
			border-bottom: #eee 1px solid;

			.card {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-top: 30rpx;
				
				.lefts {
					width: 90%;
				}
				
				.rights {
					display: flex;
					align-items: center;
				}

				img {
					width: 200rpx;
					height: 53rpx;
					margin-right: 30rpx;
					float: left;
				}

				text {
					font-size: 12px;
					line-height: 26px;
					color: #2979ff;
				}
			}

			text {
				font-size: 28rpx;
				color: #333;
			}

			h5 {
				float: left;
				font-size: 38rpx;
			}
		}

		.cash_quota {
			padding: 20rpx 0;

			text {
				font-size: 28rpx;
				color: #333;
			}

			.quota {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 30rpx 20rpx;
				border-bottom: #eee 1px solid;

				view {
					display: flex;
					align-items: center;

					input {
						padding: 15rpx;
					}
				}

				text {
					font-size: 32rpx;
					color: #fff;
					padding: 10rpx 40rpx;
					border-radius: 50rpx;
					background-color: #19be6b;
					white-space: nowrap;
				}
			}

			.withdrawal_money {
				padding-top: 20rpx;
				font-size: 26rpx;

				text {
					font-weight: bold;
					padding-left: 10rpx;
				}
			}
		}

		.cash_Tips {
			display: flex;
			flex-direction: column;
			margin-top: 30rpx;
			font-size: 24rpx;
			background-color: #f4f4f5;
			padding: 20rpx;
			color: #909399;

			text {
				margin-bottom: 10rpx;
			}
		}

		.order {
			background-color: #19be6b;
			width: 90%;
			margin: 50rpx auto;
			text-align: center;
			padding: 30rpx 0;
			border-radius: 50rpx;
			color: #fff;
			transition: all 0.5s;
		}

		.order:active {
			background-color: #75c3c5;
		}
	}
</style>